package study.datastructure.leetcode.javase.primary;/**
 * @program: datastructure
 * @author: lcy
 * @create: 2024-09-04 23:59
 */

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 2024/9/4,
 */

//CopyOnWriteArrayList
public class Client {
    public static void main(String[] args) {
        List<String> list = new CopyOnWriteArrayList<>();
        list.add("data1");
        new Thread(() -> {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            list.add("data2");
        }).start();
        new Thread(() -> {
            for (String item : list) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(item);
            }
        }).start();
    }

}
